
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'cookie'], function ($, undefined, Backend, Table, Form, Template, undefined) {
    $.cookie.prototype.defaults = { path: Config.moduleurl };
    var Controller = {
        index: function () {       // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'lease/lease/index',
                    deliver_url: 'lease/lease/deliver',
                    rent_url: 'lease/lease/rent',
                    del_url: 'lease/lease/del',
                    table: 'lease',
                },
                pageSize: 20, //调整分页大小为20
                pageList: [10, 25, 50, 100, 'All'], //增加一个100的分页大小

            });

            var table = $("#table");

            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                sortOrder: 'desc',
                search: false,
                columns: [
                    [
                        {
                            checkbox: true,
                        },
                        { field: 'id', title: __('Id'), sortable: true },
                        { field: 'product.name', title: __('Carname') },
                        { field: 'business.nickname', title: __('BusName'), operate: 'LIKE' },
                        { field: 'price', title: __('Price'), operate: '<=' },
                        { field: 'rent', title: __('Rent'), operate: '<=' },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        { field: 'endtime', title: __('Endtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        {
                            field: 'status', title: __('Status'), searchList: {  "1": __('已下单'), "2": __('已发货'), "3": __('租用中'), "4": __('已归还'),"5": __('未评价'),"6": __('已完成') }, formatter: Table.api.formatter.status
                        },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name:'detail',
                                    title:'详情',
                                    classname:'btn btn-xs btn-success btn-dialog',
                                    extend: 'data-toggle="tooltip" data-container="body"',
                                    url:'lease/lease/detail',
                                    icon:'fa fa-eye'
                                },
                                {
                                    name: 'deliver',
                                    title: '发货',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    url: $.fn.bootstrapTable.defaults.extend.deliver_url,
                                    icon: 'fa fa-leaf',
                                    visible: function (row) {
                                        if (row.status == 1 ) {
                                            return true
                                        }
                                        return false
                                    },

                                },
                                {
                                    name: 'rent',
                                    title: '退押金',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    url: $.fn.bootstrapTable.defaults.extend.rent_url,
                                    icon: 'fa fa-leaf',
                                    visible: function (row) {
                                        if (row.status == 4 ) {
                                            return true
                                        }
                                        return false
                                    },

                                },
                            ]
                        }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        del: function () {
            Controller.api.bindevent();
        },
        deliver:function(){
            Controller.api.bindevent();
        },
        rent:function(){
            $('#c-refund').change(()=>{
                if($('#c-refund').val() == 0)
                {
                    $('#examinereason').show();
                }
                else
                {
                    $('#examinereason').hide();
                }
            });
            $('#c-refund').change(()=>{
                if($('#c-refund').val() == 0)
                {
                    $('#deduct').show();
                }
                else
                {
                    $('#deduct').hide();
                }
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
})